<?php
/**
 * Created by PhpStorm.
 * User: User
 * Date: 2017/10/25
 * Time: 8:19
 */


//create function with an exception

//创建可抛出一个异常的函数
function checkNum($number)
{
    if($number>1)
    {
        throw new Exception("Value must be 1 or below");
    }
    return true;
}

//在 "try" 代码块中触发异常
try
{
    $x=new my_Exception() ;
    throw $x;
   // checkNum(2);

}

//捕获异常
catch(Exception $e)
{
    echo 'Message: ' .$e->getAllInfo();
}

class my_Exception extends  Exception{
    public function getAllInfo(){
        return "异常发生信息为:{$this->getMessage()}"."异常发生的行数{$this->getLine()}"."异常发生的代码{$this->getCode()}异常发生的方法是{$this->getFile()}";
    }
}

?>